﻿using System;
using LiSAClient.Core.Viewmodel;

namespace LiSAClient.WpfClient.ViewModel.Frame.Menus
{
    public class LeftMenuItem : MenuItemBase
    {
        public string Icon { get; private set; }

        public Func<ContentViewModel> Content { get; private set; }

        public LeftMenuItem(string displayName, string iconPath, Func<ContentViewModel> content,
            IMenuHandler menuHandler)
            : base(menuHandler)
        {
            this.Icon = iconPath;
            this.DisplayName = displayName;
            this.Content = content;

            // TODO: Implement permissions
            ////this.IsContentVisible = content != null && content.RequiredPermissions.All(x => AppContext.CurrentContext.Permissions.Contains(x));
        }

        public LeftMenuItem(
            string displayName,
            string iconPath,
            Func<ContentViewModel> content,
            IMenuHandler menuHandler,
            bool isSelectable)
            : this(displayName, iconPath, content, menuHandler)
        {
            this.IsSelectable = isSelectable;
        }

        public override void ActivateMenuAction()
        {
            base.ActivateMenuAction();
            this.MenuHandler.ActivateLeftMenuItem(this);

            if (!this.IsSelectable)
            {
                this.IsActivated = false;
            }
        }
    }
}
